/*
 * Copyright (C) 2012 Jonathan St-Michel <jonathan@abiwebz.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * ApplicationWindow.java
 *
 * Created on 2011-07-15, 10:07:30
 */
package org.abiwebz.platform.window;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.Timer;
import javax.swing.JPanel;
import javax.swing.ProgressMonitor;
import org.abiwebz.platform.util.RibbonManager;
import org.abiwebz.platform.util.job.JobManager;
import org.abiwebz.platform.view.IView;
import org.pushingpixels.flamingo.api.ribbon.JRibbon;
import org.pushingpixels.flamingo.api.ribbon.JRibbonFrame;

/**
 *
 * @author stmicj01
 */
public class ApplicationWindow extends JRibbonFrame {

    JRibbon ribbon;
    RibbonManager rm;
    
    Timer statusTimer;
    
    
    /** Creates new form ApplicationWindow */
    public ApplicationWindow() {
        initComponents();
        this.setSize(800, 600);
        this.rm = new RibbonManager(getRibbon());
        
        //Créer le jobmanager en utilisant la barre de progression de l'application
        JobManager.newInstance(progression);
        
    }
    
    public RibbonManager getRibbonManager(){
        return this.rm;
    }
    
    public void setView(IView view){
        if(view instanceof JPanel){
            this.add((JPanel)view, BorderLayout.CENTER);
        }
    }
    
    public void setStatus(String message){
        if (this.statusTimer == null) {
            this.statusTimer = new Timer(10000, new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    lStatus.setText("");
                }
            });
            this.statusTimer.setRepeats(false);
            this.statusTimer.setInitialDelay(10000);
        }
        lStatus.setText(message);
        if(this.statusTimer.isRunning())
            this.statusTimer.restart();
        else
            this.statusTimer.start();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        status = new javax.swing.JPanel();
        lStatus = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        lProgression = new javax.swing.JLabel();
        progression = new javax.swing.JProgressBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        status.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        status.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        status.add(lStatus, gridBagConstraints);

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator1.setPreferredSize(new java.awt.Dimension(5, 5));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        status.add(jSeparator1, gridBagConstraints);

        lProgression.setText("Progression");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 5);
        status.add(lProgression, gridBagConstraints);

        progression.setPreferredSize(new java.awt.Dimension(146, 15));
        status.add(progression, new java.awt.GridBagConstraints());

        getContentPane().add(status, java.awt.BorderLayout.PAGE_END);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lProgression;
    private javax.swing.JLabel lStatus;
    private javax.swing.JProgressBar progression;
    private javax.swing.JPanel status;
    // End of variables declaration//GEN-END:variables
}
